package com.wfk.plat.controller;

import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wfk.entity.OrderGoods;
import com.wfk.entity.SysCashDetails;
import com.wfk.plat.mapping.MappingUtils;
import com.wfk.service.IOrderGoodsService;
import com.wfk.service.ISysCashDetailsService;
import com.wfk.utils.BasePage;
import com.wfk.utils.ObjectToFileXSL;

@Controller
public class DownloadController {
	@Autowired
	private ISysCashDetailsService sysCashDetailsService;
	@Autowired
	private IOrderGoodsService orderGoodsService;
	
	@RequestMapping(value=MappingUtils.downloadOrderList)
	public void downloadOrderGoods(HttpServletRequest request,HttpServletResponse response,BasePage<OrderGoods> page,OrderGoods orderGoods) {
		ObjectToFileXSL xsl =  new ObjectToFileXSL(""+System.currentTimeMillis());
		try {
			page.setPage(false);
			orderGoodsService.getList(page,orderGoods);
			String[] texts = {"订单编号:orderid","支付方订单号:paycode","会员ID:cid","商品:title","规格:specName"
					,"收货人姓名:name","收货人电话:phone","收获人地址:address","数量:qty","单价:price"
					,"支付金额:paymoney","支付方式:paytype|1.支付宝,2.微信,3.余额,4.银联"
					,"状态:status|0.未支付,1.待发货,2.已发货,3.已完成","支付时间:paytime","创建时间:createtime"};
			OutputStream output = response.getOutputStream();
			response.reset();
			response.setContentType("application/multipart");
			response.setHeader("Content-Disposition", "attachment;filename="+"车险订单"+ System.currentTimeMillis() + ".xls");
			xsl.WriteIn(texts,page.getRecords(),output);
			output.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value=MappingUtils.downloadCashList)
	public void downloadCash(HttpServletRequest request,HttpServletResponse response,BasePage<SysCashDetails> page,SysCashDetails sysCashDetails) {
		ObjectToFileXSL xsl =  new ObjectToFileXSL(""+System.currentTimeMillis());
		try {
			page.setPage(false);
			sysCashDetailsService.getList(sysCashDetails,page);
			String[] texts = {"会员ID:targetid","开户行姓名:realname","银行名称:bankname"
					,"银行卡号:bankcode","手机号码:phone","提现金额:cashmoney","实际到账:realmoney"
					,"创建时间:createtime","处理时间:endtime","状态:status|1.待审核,2.审核通过,3.审核驳回"};
			OutputStream output = response.getOutputStream();
			response.reset();
			response.setContentType("application/multipart");
			response.setHeader("Content-Disposition", "attachment;filename="+"车险订单"+ System.currentTimeMillis() + ".xls");
			xsl.WriteIn(texts,page.getRecords(),output);
			output.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
